package com.boco.blch.dispatcher.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileUtil {
	private final static SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
	private final static char[] CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
	public static String getDate() {
		return DEFAULT_DATE_FORMAT.format(new Date());
	}


	public static String generateMixed(int n) {
		StringBuilder res = new StringBuilder();
		for (int i = 0; i < n; i++) {
			double id = Math.ceil(Math.random() * 35);
			res.append(CHARS[(int)id]);
		}
		return res.toString();
	}
	
	

	
	
	public static String readFile(String path)  {
		BufferedInputStream bis = null;
		try{
			File file = new File(path);
			bis = new BufferedInputStream(new FileInputStream(file));
			int length = 0;
			byte[] buffer = new byte[1024];
			StringBuilder sb = new StringBuilder();
			while((length = bis.read(buffer)) != -1){
				sb.append(new String(buffer, 0, length));
			}
			return sb.toString();
		} catch(IOException e) {
			e.printStackTrace();
			return null;
		} finally {
			try {
				bis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) throws UnsupportedEncodingException {
		System.out.println(URLDecoder.decode("%D6%F7%BB%FA%CD%A8%B6%CF%E5%B4%BB%FA%CA%B1%BC%E4%CD%B3%BC%C6", "gbk"));
	}
	
}
